﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nancy;
using Nancy.Security;
using Nancy.ModelBinding;
using PlatWL.Data;
using PlatWL.Services.ServicesWeb;

namespace PlatWL.Modules.Web
{
    public class UserModule : MsgModule
    {
        public UserModule(UserManage service) : base("user")
        {
            this.RequiresAuthentication();
            #region 用户信息
            //获取用户基本信息
            Get["/userinfo"] = p =>
            {
                msg.result = new
                {
                    ID = user_account.ID,
                    Telephone = user_account.Telephone,
                    UserType = user_account.UserType,
                    NickName = user_account.NickName,
                    TrueName = user_account.TrueName,
                    UserImg = user_account.UserImg,
                    Point = user_account.Point,//存钱罐余额
                    Attach1 = user_account.Attach1,
                    Attach2 = user_account.Attach2,
                    Attach3 = user_account.Attach3
                };
                return Response.AsJson(msg);
            };
            //修改用户信息
            Post["updateuserinfo"] = p => {
                var urs = this.Bind<pt_user_account>();
                service.UpdateUserInfo(ref msg, Client, user_account, urs);
                return Response.AsJson(msg);
            };
            #endregion
            #region 地址管理
            //添加地址
            Post["/address/add"] = p =>
            {
                var ad = this.Bind<pt_user_address>();
                service.AddModel(ref msg, Client, user_account, ad);
                return Response.AsJson(msg);
            };
            //获取地址
            Get["/address/model/{id:int}"] = p =>
            {
                service.GetModel(ref msg, Client, p.id);
                return Response.AsJson(msg);
            };
            //默认地址
            Get["/address/first"] = p =>
            {
                service.GetAddressFirst(ref msg, Client, user_account);
                return Response.AsJson(msg);
            };
            //地址列表
            Get["/address/list"] = p =>
            {
                service.GetAddressList(ref msg, Client, user_account);
                return Response.AsJson(msg);
            };
            //删除地址
            Get["/address/del/{id:int}"] = p =>
            {
                service.DelModel(ref msg, Client, user_account, p.id);
                return Response.AsJson(msg);
            };
            //设置默认
            Get["/address/setdefault/{id:int}"] = p =>
            {
                service.SetDefault(ref msg, Client, user_account, p.id);
                return Response.AsJson(msg);
            };
            #endregion
            #region 积分管理
            Get["/point/list"] = p =>
            {
                //service.GetPointList(ref msg, Client, page, user_account);
                return Response.AsJson(msg);
            };
            #endregion
            #region 我的收藏
            Get["/shoucang/list"] = p =>
            {
               
                return Response.AsJson(msg);
            };
            Get["/shoucang/del/{id:int}"] = p =>
            {
                
                return Response.AsJson(msg);
            };
            #endregion


        }
    }
}